﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CRM_SMS_MARKETING.DAL;
using ConnectDatabase;
using CRM_SMS_MARKETING.EL;
using System.Data;

namespace CRM_SMS_MARKETING.DAL
{
    class DALUser
    {
        ConnectDB con;
        public List<ELUser> getListUser()
        {
            try
            {
                List<ELUser> ListUser = new List<ELUser>();
                con = new ConnectDB("Data Source=THE-VAIO\\DDNI;Initial Catalog=CRM_SMS;Integrated Security=True");
                DataTable tuser = con.getTable("SELECT * FROM [UserAccount]");
                ELUser user;
                foreach (DataRow i in tuser.Rows)
                {
                    user = new ELUser();

                    #region mapping
                    user.UserID = (int)i["UserID"];
                    user.UserName = i["UserName"].ToString();
                    user.Password = i["Password"].ToString();
                    user.Name = i["Name"].ToString();
                    user.CellPhone = i["CellPhone"].ToString();
                    user.Gender = (bool)i["Gender"];
                    user.Birthday = (DateTime)i["Birthday"];
                    user.Address = i["Address"].ToString();
                    user.District = i["District"].ToString();
                    user.City = i["City"].ToString();
                    user.Phone = i["HomePhone"].ToString();
                    user.Email = i["Email"].ToString();
                    #endregion

                    //addCustomer(customer);
                    ListUser.Add(user);
                }

                return ListUser;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List<ELSmallUser> GetListUserName()
        {
            try
            {
                List<ELSmallUser> ListUserName = new List<ELSmallUser>();
                con = new ConnectDB("Data Source=THE-VAIO\\DDNI;Initial Catalog=CRM_SMS;Integrated Security=True");
                DataTable tuser = con.getTable("SELECT UserID,UserName FROM [UserAccount]");
                 
                foreach (DataRow i in tuser.Rows)
                {
                    ELSmallUser UserName = new ELSmallUser();
                    UserName.UserID = (int)i["UserID"];
                    UserName.UserName = i["UserName"].ToString();


                    //addCustomer(customer);
                    ListUserName.Add(UserName);
                }

                return ListUserName;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
